package com.manager.opecourse;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

@SuppressWarnings("serial")
public class OptCourse extends Model<OptCourse> {

	public static final OptCourse me = new OptCourse();

	/**
	 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public Page<OptCourse> paginate(int sid, int pageNumber, int pageSize) {
		return paginate(pageNumber, pageSize, "select o.id, b.course_name, b.teacher_name ",
				"from opt_course o LEFT JOIN (select c.id, c.course_name, t.teacher_name from course c LEFT JOIN teacher t on c.tid = t.id ) as b  on o.cid = b.id where o.sid = ? order by o.id asc",
				sid);
	}

	public OptCourse findEditById(int id) {
		return findFirst(
				"select c.id, c.course_name, t.id as tid, t.teacher_name from course c left join teacher t on c.tid = t.id where c.id = ?",
				id);
	}

}
